<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件流</title>
    <style>
        .father {
            width: 400px;
            height: 400px;
            background: pink;
        }
        .son {
            width: 200px;
            height: 200px;
            margin: 0 auto;
            background-color: red;
        }
    </style>
</head>
<body>
    <div class="father">
        <div class="son"></div>
    </div>
    <script>
        // 1. 捕获阶段 如果 第三个参数是true document -> html -> body -> father -> son
        // var son = document.querySelector('.son');
        // son.addEventListener('click',function() {
        //     alert('son')
        // },true)
        // var father = document.querySelector('.father');
        // father.addEventListener('click',function() {
        //     alert('father')
        // },true)

         // 2. 冒泡阶段 如果 第三个参数是false son -> father -> body -> html -> document
         var son = document.querySelector('.son');
        son.addEventListener('click',function(e) {
            alert('son');
            e.stopPropagation(); //  常用！！ stop停止  propagation 传播
            e.cancelBubble = true; // 非标准  cancel 取消 bubble 泡泡
        },false)
        var father = document.querySelector('.father');
        father.addEventListener('click',function() {
            alert('father')
        },false)
        document.addEventListener('click',function(){
            alert('document')
        })
    </script>
</body>
</html>